package org.bspv.pharma.business.impl;

import java.util.List;

import org.bspv.pharma.business.AdministrationBusinessService;
import org.bspv.pharma.manager.CategoryManager;
import org.bspv.pharma.manager.DrugstoreManager;
import org.bspv.pharma.manager.PackagingManager;
import org.bspv.pharma.manager.PlaceManager;
import org.bspv.pharma.manager.StandardEquipmentDetailManager;
import org.bspv.pharma.manager.StandardEquipmentManager;
import org.bspv.pharma.manager.TypeOfSupplyManager;
import org.bspv.pharma.model.Category;
import org.bspv.pharma.model.Drugstore;
import org.bspv.pharma.model.Packaging;
import org.bspv.pharma.model.Place;
import org.bspv.pharma.model.StandardEquipment;
import org.bspv.pharma.model.StandardEquipmentDetail;
import org.bspv.pharma.model.TypeOfSupply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @author guillaume
 * 
 */
@Service(value = "administrationBusinessService")
public class AdministrationBusinessServiceImpl implements AdministrationBusinessService {

    @Autowired
    private DrugstoreManager drugstoreManager;
    @Autowired
    private CategoryManager categoryManager;
    @Autowired
    private PackagingManager packagingManager;
    @Autowired
    private PlaceManager placeManager;
    @Autowired
    private TypeOfSupplyManager typeOfSupplyManager;
    @Autowired
    private StandardEquipmentManager standardEquipmentManager;
    @Autowired
    private StandardEquipmentDetailManager standardEquipmentDetailManager;

    /**
     * @param drugstoreManager
     *            the drugstoreManager to set
     */
    public void setDrugstoreManager(DrugstoreManager drugstoreManager) {
        this.drugstoreManager = drugstoreManager;
    }

    /**
     * @param categoryManager
     *            the categoryManager to set
     */
    public void setCategoryManager(CategoryManager categoryManager) {
        this.categoryManager = categoryManager;
    }

    /**
     * @param packagingManager
     *            the packagingManager to set
     */
    public void setPackagingManager(PackagingManager packagingManager) {
        this.packagingManager = packagingManager;
    }

    /**
     * @param placeManager
     *            the placeManager to set
     */
    public void setPlaceManager(PlaceManager placeManager) {
        this.placeManager = placeManager;
    }

    /**
     * @param typeOfSupply
     *            the typeOfSupply to set
     */
    public void setTypeOfSupplyManager(TypeOfSupplyManager typeOfSupplyManager) {
        this.typeOfSupplyManager = typeOfSupplyManager;
    }

    /**
     * @param standardEquipmentManager
     *            the standardEquipmentManager to set
     */
    public void setStandardEquipmentManager(StandardEquipmentManager standardEquipmentManager) {
        this.standardEquipmentManager = standardEquipmentManager;
    }

    /**
     * @param standardEquipmentDetailManager
     *            the standardEquipmentDetailManager to set
     */
    public void setStandardEquipmentDetailManager(StandardEquipmentDetailManager standardEquipmentDetailManager) {
        this.standardEquipmentDetailManager = standardEquipmentDetailManager;
    }

    /**
     * DRUGSTORE METHODS
     */

    public Drugstore findDrugstore(String id) {
        return drugstoreManager.findById(id);
    }

    public void deleteDrugstoreById(String id) {
        Drugstore drugstore = drugstoreManager.findById(id);
        drugstoreManager.delete(drugstore);
    }

    public List<Drugstore> findAllDrugstores() {
        return drugstoreManager.findAll();
    }

    public Drugstore saveDrugstore(Drugstore drugstore) {
        return drugstoreManager.save(drugstore);
    }

    /**
     * CATEGORY METHODS
     */

    public void deleteCategoryById(Long id) {
        Category category = categoryManager.findById(id);
        categoryManager.delete(category);
    }

    public List<Category> findAllCategories() {
        return categoryManager.findAll();
    }

    public Category findCategory(Long id) {
        return categoryManager.findById(id);
    }

    public Category saveCategory(Category category) {
        return categoryManager.save(category);
    }

    /**
     * PACKAGING METHODS
     */

    public void deletePackagingById(Long id) {
        Packaging packaging = packagingManager.findById(id);
        packagingManager.delete(packaging);
    }

    public List<Packaging> findAllPackaging() {
        return packagingManager.findAll();
    }

    public Packaging findPackaging(Long id) {
        return packagingManager.findById(id);
    }

    public Packaging savePackaging(Packaging packaging) {
        return packagingManager.save(packaging);
    }

    /**
     * PLACE METHODS
     */

    public void deletePlaceById(Long id) {
        Place place = placeManager.findById(id);
        placeManager.delete(place);
    }

    public List<Place> findAllPlaces() {
        return placeManager.findAll();
    }

    public Place findPlace(Long id) {
        return placeManager.findById(id);
    }

    public Place savePlace(Place place) {
        return placeManager.save(place);
    }

    /**
     * TYPE_OF_SUPPLY METHODS
     */

    public void deleteTypeOfSupplyById(Long id) {
        TypeOfSupply typeOfSupply = typeOfSupplyManager.findById(id);
        typeOfSupplyManager.delete(typeOfSupply);
    }

    public List<TypeOfSupply> findAllTypeOfSupplies() {
        return typeOfSupplyManager.findAll();
    }

    public TypeOfSupply findTypeOfSupply(Long id) {
        return typeOfSupplyManager.findById(id);
    }

    public TypeOfSupply saveTypeOfSupply(TypeOfSupply typeOfSupply) {
        return typeOfSupplyManager.save(typeOfSupply);
    }

    /**
     * STANDARD_EQUIPMENT METHODS
     */

    public void deleteStandardEquipmentById(Long id) {
        StandardEquipment standardEquipment = standardEquipmentManager.findById(id);
        standardEquipmentManager.delete(standardEquipment);
    }

    public List<StandardEquipment> findAllStandardEquipments() {
        return standardEquipmentManager.findAll();
    }

    public StandardEquipment findStandardEquipment(Long id) {
        return standardEquipmentManager.findById(id);
    }

    public StandardEquipment saveStandardEquipment(StandardEquipment standardEquipment) {
        return standardEquipmentManager.save(standardEquipment);
    }

    public List<StandardEquipment> findStandardEquipments(List<Place> places) {
        return standardEquipmentManager.findStandardEquipments(places);
    }

    public List<StandardEquipmentDetail> findStandardEquipmentDetails(StandardEquipment element) {
        return standardEquipmentDetailManager.findDetails(element);
    }

    public List<StandardEquipmentDetail> saveStandardEquipmentDetails(List<StandardEquipmentDetail> details) {
        return standardEquipmentDetailManager.save(details);
    }
}
